<template>
  <div class="search_f">
    <!-- 搜索框 -->
    <div class="search">
      <input v-model="search" type="text" placeholder="搜索商家，搜索店铺" />
      <!-- <input v-model="search" type="text" value="凉皮" /> -->
      <span @click="search_v()">搜索</span>
    </div>
    <!-- 历史记录与商品列表只显示其一 -->
    <div class="history" v-if="search == ''">
      <h3>历史记录</h3>
      <div class="record">
        <span class="neir" v-for="(item, index) in historyArr" :key="index">{{
          item
        }}</span>
      </div>
    </div>
    <!-- 搜索列表 -->
    <div class="searchlist" v-else>
      <div class="sort">
        <span v-for="(item, index) in sortArr" :key="index">{{ item }}</span>
      </div>
      <!-- 店铺信息 -->
      <div class="goods" v-for="(item, index) in Productlist" :key="index">
        <img class="goods_img" :src="item.picUrl" alt="" />
        <div class="goodname">
          <h4>{{ item.name }}</h4>
          <!-- 评分 -->
          <div class="good2">
            <div class="g_left">
              <span class="col">★{{ item.wmPoiScore }}</span>
              <span>{{ item.monthSalesTip }}</span>
              <span>{{ item.minPriceTip }}</span>
            </div>
            <div class="g_right">
              <span>{{ item.deliveryTimeTip }}</span>
              <span>{{ item.distance }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { List } from "vant";
import { shop_search } from "../utils/api";
export default {
  data() {
    return {
      historyArr: [],
      // 搜索结果
      Productlist: {},
      search: "",
      sortArr: ["综合排序", "销量最高", "距离最近", "筛选"],
    };
  },
  mounted() {
    //searchkey
    this.historyArr = this.$store.state.historyArr;
  },
  methods: {
    search_v() {
      if (this.search != "") {
        this.$store.commit("historylist", this.search);
        let content = this.search;
        shop_search({ searchkey: content }).then((res) => {
          this.Productlist = res.data.list;
        });
        // 清空
        // this.search = "";
      } else {
        this.Productlist = {};
      }

    },
  },
};
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}
.search_f {
  padding: 10px 10px;
}

.search {
  width: 100%;
  height: 50px;
  line-height: 50px;
  display: flex;
  justify-content: space-between;
  input {
    font-size: 14px;
    height: 30px;
    flex: 4;
    border-radius: 15px;
    padding: 0 10px;
    border: 0;
    margin: 10px 0;
    background-color: #eee;
  }
  span {
    margin: 1px;
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: rgb(65, 130, 227);
  }
}

.history {
  h3 {
    font-size: 18px;
    line-height: 40px;
  }
  .record {
    height: 100px;

    .neir {
      padding: 2px 5px;
      background-color: #eee;
      border-radius: 3px;
      font-size: 14px;
      margin: 4px 5px;
      float: left;
    }
  }
}
.searchlist {
  .sort {
    display: block;
    width: 100%;
    height: 50px;
    span {
      padding: 2px 4px;
      background-color: #eee;
      border-radius: 3px;
      margin: 5px;
      font-size: 14px;
    }
  }
  .goods {
    display: flex;
    margin: 10px 0;
    img {
      width: 50px;
      height: 50px;
      margin-right: 10px;
      border: 1px solid #999;
      border-radius: 3px;
    }
    .goodname {
      flex: 1;
      .good2 {
        display: flex;
        justify-content: space-between;
        font-size: 12px;
        span {
          margin: 2px 3px;
        }
        .g_left {
          .col {
            color: chocolate;
          }
        }
      }
    }
  }
}
</style>